package com.linkhub.oms.admin.config;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

/**
 * @Description: DataSourceConfig
 * @Author: echo
 * @Date: 2024/3/3 09:24
 * @Version: 1.0
 */
@Configuration
public class DataSourceConfig {

    public static final String LINKHUB_DATA_SOURCE = "linkhubDataSource";

    @Bean(name = LINKHUB_DATA_SOURCE)
    @Qualifier(LINKHUB_DATA_SOURCE)
    @Primary // 定义主数据源
    @ConfigurationProperties(prefix = "linkhub.datasource", ignoreInvalidFields = true)
    public DataSource primaryDataSource() {
        return DataSourceBuilder.create().build();
    }
}
